import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:massagist/pages/phone_auto_page.dart';
import 'package:massagist/pages/privacy_page.dart';
import 'package:massagist/pages/splash_page.dart';

import 'generated/l10n.dart';

void main() {
  // WidgetsFlutterBinding.ensureInitialized(); // 确保初始化
  // SystemChrome.setPreferredOrientations([
  //   DeviceOrientation.portraitUp,
  // ]);

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context , child) {
        return MaterialApp(
          localizationsDelegates: [S.delegate],
            localeResolutionCallback:
                (Locale? locale, Iterable<Locale> supportedLocales) {
              var result = supportedLocales
                  .where((element) => element.languageCode == locale?.languageCode);
              if (result.isNotEmpty) {
                print(locale?.languageCode);
                // return locale;
                return Locale('en');
              }
              return Locale('en');
            },
          supportedLocales: S.delegate.supportedLocales,
          debugShowCheckedModeBanner: false,
          title: 'First Method',
          // You can use the library anywhere in the app even in theme
          theme: ThemeData(
            primarySwatch: Colors.blue,
            textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
          ),
          home: child,
        );
      },
      child: new SplashPage(),
    );
  }
}
